/*
 * Copyright:  2018 smarabbit studio.
 *
 *  Licensed under the Confluent Community License; you may not use this file
 *  except in compliance with the License.  You may obtain a copy of the License at
 *
 *  http://www.confluent.io/confluent-community-license
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 *  WARRANTIES OF ANY KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations under the License.
 *
 *  @作   者： 黄开晖 (117227773@qq.com)
 *  @日   期:  2020年9月3日
 */
package com.massyframework.beanskin.service;

/**
 * 对{@link ServiceListener}的封装。
 * 
 * @author huangkh
 */
public abstract class ServiceEventAdapter implements ServiceListener {

	/**
	 * 构造方法
	 */
	public ServiceEventAdapter() {
	}

	/**
     * 处理服务已注册事件
     * @param event {@link ServiceRegistedEvent}, 服务已注册事件
     */
    protected void onRegistedEvent(ServiceRegistedEvent<?> event){

    }

    /**
     * 处理服务注销事件
     * @param event {@link ServiceUnregistingEvent}, 服务注销事件
     */
    protected void onUnregistingEvent(ServiceUnregistingEvent<?> event){

    }

    /**
     * 当<code>event</code>事件触发时，对事件进行处理
     *
     * @param event {@link ServiceEvent}
     */
    @Override
    public final void onChanged(ServiceEvent<?> event) {
        Class<?> eventType = event.getClass();
        if (ServiceRegistedEvent.class == eventType){
            this.onRegistedEvent((ServiceRegistedEvent<?>)event);
            return;
        }

        if (ServiceUnregistingEvent.class == eventType){
            this.onUnregistingEvent((ServiceUnregistingEvent<?>)event);
            return;
        }
    }
}
